package com.guanyu.u2cache.model;

import cn.hutool.core.lang.Pair;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author zhouyunjian
 * @date 2023/12/08 17:29
 * 缓存使用类
 **/
@Data
public class MemoryUseClass {

    public MemoryUseClass() {
        this.key = new ArrayList<>(100);
    }

    /***缓存名**/
    private Object cacheNames;
    /***缓存大小**/
    private Long size = 0L;
    /***缓存key与大小**/
    private List<MemoryHotKey> key;

    public void addKeyInfo(long size, String key, Map<String, Long> map) {
        this.key.add(new MemoryHotKey(size, key, map));
    }

    @Data
    class MemoryHotKey {
        /***缓存名**/
        private String key;
        /***缓存总大小**/
        private Long size;
        /***使用频率**/
        private Long hotTotalCount = 0L;
        /***时间、次数映射关系**/
        private List<Pair<String, Long>> sportTimes;

        public MemoryHotKey(long size, String key, Map<String, Long> map) {
            this.size = size;
            this.key = key;
            this.sportTimes = new ArrayList<>(100);
            map.forEach((k, v) -> {
                this.sportTimes.add(Pair.of(k, v));
                this.hotTotalCount += v;
            });
        }
    }

}
